package lv.dysnomia.portal.web;

import java.io.IOException;
import java.util.Date;
import java.util.logging.Logger;
import javax.jdo.PersistenceManager;
import javax.servlet.http.{HttpServlet,HttpServletRequest,HttpServletResponse}
import com.google.appengine.api.users.{User,UserService,UserServiceFactory}


class SignGuestbookServlet extends HttpServlet {
    val log = Logger.getLogger("lv.dysnomia.portal.web.SignGuestbookServlet")

    override def doPost(request:HttpServletRequest, response:HttpServletResponse) = {
        val userService = UserServiceFactory.getUserService
        val user = userService.getCurrentUser

        val content = request.getParameter("content")
        val date = new Date
        val greeting = new Greeting(user, content, date)

        val pm = PMF.getInstance.getPersistenceManager
        try {
            pm.makePersistent(greeting)
        } finally {
            pm.close()
        }

        response sendRedirect "/guestbook.jsp"
    }
}